package cn.portx.view;

import java.util.List;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import cn.portx.entity.Customer;
import cn.portx.entity.Memorandum;
import cn.portx.entity.Order;

import com.bstek.bdf3.dorado.jpa.JpaUtil;
import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.DataResolver;
import com.bstek.dorado.annotation.Expose;
import com.bstek.dorado.data.provider.Criteria;
import com.bstek.dorado.data.provider.Page;

@Component
public class MemorandumPR {

	@DataProvider
	@Transactional(readOnly = true)
	public Order loadOrder(String orderId) {
		List<Order> list =JpaUtil.linq(Order.class).equal("id",orderId).collect(Customer.class, "customerId").list();
		return list.isEmpty()?null:list.get(0);
	}
	
	@DataProvider
	@Transactional(readOnly = true)
	public void loadMemorandum(Page<Memorandum> page, Criteria criteria,String orderId) {
		JpaUtil.linq(Memorandum.class).equal("orderId", orderId).desc("createDate").where(criteria).paging(page);
	}
	
	@DataResolver
	@Transactional
	public void saveMemorandum(List<Memorandum> list) {
		JpaUtil.save(list);
	}
	

	@Expose
	@Transactional
	public void deleteMemorandum(String id) {
		JpaUtil.lind(Memorandum.class).equal("id", id).delete();
	}
}
